<template>
    <div>
        <h3>ajax Sync Post</h3>
        <div>userName: {{ ajaxRet.userName }}</div>
        <div>userId: {{ ajaxRet.userId }}</div>
        <div>password: {{ ajaxRet.password }}</div>
        <div>
            <button @click="ajaxPost">测试同步Ajax Post</button>
        </div>

    </div>
</template>
<script>
    import {API} from '@/http/api';
    export default {
        components: {

        },
        props: {

        },
        data () {
            return {
                ajaxRet: {
                    userName: "",
                    userId: "",
                    password: ""
                }
            }
        },
        mounted(){

        },
        /**
         * 计算属性
         */
        computed: {

        },
        methods: {
            ajaxPost: async function() {
                await API.hello({
                    name: "xiao.hu"
                }).then((response) => {
                    let data = response.data;
                    console.log(JSON.stringify(data));

                    this.ajaxRet.userName = data.userName;
                    this.ajaxRet.userId = data.userId;
                    this.ajaxRet.password = data.password;
                    window.alert("获取了结果");
                }).catch((error) => {
                    console.log(error);
                });
                window.alert("获取了结果之后，再打印此语句");
            }
        }
    }
</script>
<style scoped>

</style>